package com.blrs.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.common.core.domain.entity.SysUser;
import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.domain.FileCabinetInformation;
import com.blrs.system.mapper.SysUserMapper;
import com.blrs.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.InternalDocument;
import com.blrs.service.file.IInternalDocumentService;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 内部文件Controller
 * 
 * @author ruoyi
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/file/internal")
public class InternalDocumentController extends BaseController
{
    @Autowired
    private IInternalDocumentService internalDocumentService;


    /**
     * 查询内部文件柜树形列表
     */
    @GetMapping("/listFileTree")
    public AjaxResult listFileTree(FileCabinetInformation fileCabinetInformation)
    {
        /*Long userid = SecurityUtils.getUserId();
        if(userid!=1){

        }*/
        fileCabinetInformation.setBelongTo(SecurityUtils.getOrgId());
        List<Map> list = internalDocumentService.getFileTree(fileCabinetInformation);
        return success(list);
    }
    /**
     * 查询内部文件列表
     */

    @GetMapping("/list")
    public TableDataInfo list(InternalDocument internalDocument)
    {
        startPage();
        List<InternalDocument> list = internalDocumentService.selectInternalDocumentList(internalDocument);
        return getDataTable(list);
    }

    /**
     * 导出内部文件列表
     */

    @Log(title = "内部文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InternalDocument internalDocument)
    {
        List<InternalDocument> list = internalDocumentService.selectInternalDocumentList(internalDocument);
        ExcelUtil<InternalDocument> util = new ExcelUtil<InternalDocument>(InternalDocument.class);
        util.exportExcel(response, list, "内部文件数据");
    }

    /**
     * 获取内部文件详细信息
     */

    @GetMapping(value = "/{internalId}")
    public AjaxResult getInfo(@PathVariable("internalId") String internalId)
    {
        return success(internalDocumentService.selectInternalDocumentByInternalId(internalId));
    }

    /**
     * 新增内部文件
     */

    @Log(title = "内部文件", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult add(@RequestBody InternalDocument internalDocument)
    {
        return toAjax(internalDocumentService.insertInternalDocument(internalDocument));
    }

    /**
     * 修改内部文件
     */

    @Log(title = "内部文件", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult edit(@RequestBody InternalDocument internalDocument)throws NoSuchFieldException, IllegalAccessException
    {
        return toAjax(internalDocumentService.updateInternalDocument(internalDocument));
    }

    /**
     * 删除内部文件
     */

    @Log(title = "内部文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{internalIds}")
    public AjaxResult remove(@PathVariable String[] internalIds)
    {
        return toAjax(internalDocumentService.deleteInternalDocumentByInternalIds(internalIds));
    }
}
